#include <stdio.h>
#include <iostream>
#include "libutils.h"
#include "protocol.h"
#include "dlt645.h"

using namespace std;

int main(void)
{
#if 0
	int i = 0;

	for(i = 0; i < 20; ++i) {
		printf("%d\n", get_random());
	}

	cout<<endl;
	int a = 25;
	printf("%d\n", bin2bcd(a));
	int b = 37;
	printf("%d\n", bcd2bin(b));

	//char *str = "012345ABCDEabcde";

	//mem_dump(str, strlen(str));

	cout<<"Get fn"<<endl;

	__u8 dt1 = 0x80, dt2 = 0x2;
	printf("%02d\n", GetFn(dt1, dt2));
	
	{
		__u8 fn = 24, dt1, dt2;
		SetFn(fn, &dt1, &dt2);
		printf("%02d %02d\n", dt1, dt2);
	}

	//68 99 99 99 99 99 99 68 08 04 33 33 33 33 3E 16

	__u8 buf[] = {0x68, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x68, 0x08,
		0x04, 0x33, 0x33, 0x33, 0x33, 0x3E, 0x16};
	
	if(dlt645_valid_check((dlt645 *)buf, sizeof(buf)/sizeof(__u8)) == 0)
		puts("yes");
	else
		puts("no");
	
	__u8 input[256];
	cin>>input;
	__u8 *p = (__u8*)malloc(128);

	str2hex(input, p, strlen((char*)input));

	mem_dump(p, strlen((char*)input)/2);
	free(p);
#endif
	{
		//char *p = "001010050505";
		unsigned char *str = (unsigned char *)malloc(6);
		str[0] = 0x00;
		str[1] = 0x10;
		str[2] = 0x10;
		str[3] = 0x05;
		str[4] = 0x05;
		str[5] = 0x05;
		time_t t = unix_time(str);
		printf("%d\n", t);
		printf("%s\n", ctime(&t));
	}

	return 0;
}

